/**
 * @author scylla
 * @version V1.0
 * @Project echo-java-base
 * @Title 内置可运行线程  实现runable
 * @Description *
 * @Package concurrent.mthread.self
 * @Since 2021/7/29 1:25 下午
 */
package concurrent.mthread.self;

import java.util.concurrent.TimeUnit;

public class InnerRunnable2 {
    private int countDown = 5;
    private Thread t;

    public InnerRunnable2(String name) {
        t = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println(this);
                    if (--countDown == 0) return;

                    TimeUnit.MILLISECONDS.sleep(10);
                } catch (InterruptedException e) {
                    System.err.println(e.getMessage());
                }
            }

            @Override
            public String toString() {
                return t.getName() + ": " + countDown;
            }
        }, name);

        t.start();
    }

}
